<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id: TagLibHtml.class.php 2730 2012-02-12 04:45:34Z liu21st $

/**
 +-------------------------------
 * Html标签库驱动
 +-------------------------------
 */
class TagLibHtml extends TagLib{
    // 标签定义
    protected $tags   =  array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'editor'       => array('attr'=>'id,name,style,width,height,type','close'=>1),
        'select'      => array('attr'=>'style,name,options,values,output,multiple,id,size,first,change,selected,dblclick','close'=>0),
        'grid'          => array('attr'=>'id,pk,style,action,actionlist,show,datasource','close'=>0),
        'list'           => array('attr'=>'id,pk,style,action,actionlist,show,datasource,checkbox','close'=>0),
        'imagebtn'  => array('attr'=>'id,name,value,type,style,click','close'=>0),
        'checkbox'  => array('attr'=>'name,checkboxes,checked,separator','close'=>0),
        'radio'        => array('attr'=>'name,radios,checked,separator','close'=>0),
		'listselect'           => array('attr'=>'name,datatype,id,class,style,title,datatype,url,multiple,selected,anothername','close'=>0),
		'dropdownselect'           => array('attr'=>'listloaded,typelimit,placeholder,name,datatype,id,class,style,title,datatype,action,multi,selected,anothername,height,width','close'=>0),
		'uploadimg'      => array('attr' => 'url,text,name,id,style,value,class,type', 'close' => 0),
		'headupload'      => array('attr' => 'rotateaction,width,height,uploadaction,jcropaction,aspectRatio,url,text,name,id,style,value,class,type', 'close' => 0),
        );
		
		/**
     * 获得一个上传组件
     */
    public function _uploadimg($attr)
    {
		$attr        =	$this->parseXmlAttr($attr,'uploadimg');
        $id = $attr['id'];
        $name = $attr['name'];
		$value = $attr['value'];
		$num = !empty($attr['num']) ? $attr['num'] : 1;
		$url = !empty($attr['url']) ? $attr['url'] : 'Index/uploadimg';
		$name1 = md5($name);
		$text = !empty($attr['text']) ? $attr['text'] : '选择文件上传';
		
		if(strpos($name, '$') === 0){
			$name = '{'.$name.'}';
		}
		$sort = '';
		if($num > 1){
			$sort = '<div class="sort"><a href="##" class="fa fa-chevron-right"></a><a href="##" class="fa fa-chevron-left"></a></div>';
		}
		
		if(!empty($value)){
			$listhtml = '<?php if(strpos('.$value.', ",")){
			$list'.$name1.' = explode(",", '.$value.');
		}else{
			$list'.$name1.'[0] = '.$value.';
		}

		if($list'.$name1.'[0] == "" && count($list'.$name1.') == 1){
			$list'.$name1.' = array();
		} 
		foreach($list'.$name1.' as $v){
			?>
			<div class="dz-preview dz-processing dz-image-preview dz-success success dz-complete">'.$sort.'<input type="hidden" name="'.$name.'" value="<?php echo $v;?>">  <div class="dz-image"><img alt="图片" src="/Public<?php echo $v;?>"></div> <a class="dz-remove" href="javascript:undefined;" data-dz-remove="">移除</a></div>
		<?php }?>';
		}else{
			$listhtml = NULL;
		}
		$parseStr = '
		<a href="##" class="btn btn-success btn-sm" id="dropz'.$id.'">'.$text.'</a>
<div class="dropzonebox dropzonebox'.$id.'">
'.$listhtml.'   

</div>
         
		 <script>
		 
		 function '.$id.'addLoadEventtagUpload(func) { 
			var oldonload = window.onload; 
				if (typeof window.onload != \'function\') { 
				    window.onload = func;
				} else {
				window.onload = function() { 
				    oldonload();
				func(); 
				} 
			} 
		}
		'.$id.'addLoadEventtagUpload(function(){
		var dropzonebox'.$id.' = $("#dropz'.$id.'").dropzone({
        url: "{:U(\''.$url.'\')}", //必须填写
        method:"post",  //也可用put
        paramName:"file", //默认为file
        maxFiles:'.$num.',//一次性上传的文件数量上限
        maxFilesize: 20, //MB
        acceptedFiles: "", //上传的类型
        previewsContainer:".dropzonebox'.$id.'", //显示的容器
		addRemoveLinks:true,
        parallelUploads: 3,
        dictMaxFilesExceeded: "您最多只能上传'.$num.'个文件！",
        dictResponseError: \'文件上传失败!\',
		dictRemoveFile:"移除",
		dictRemoveFileConfirmation:"确定要移除这个图片吗？",
        dictInvalidFileType: "你不能上传该类型文件,文件类型只能是*.jpg,*.gif,*.png。",
        dictFallbackMessage:"浏览器不受支持",
        dictFileTooBig:"文件过大上传文件最大支持.",
        previewTemplate: \'<div class="dz-preview dz-file-preview">'.$sort.'<input type="hidden" name="'.$name.'" value="">\n  <div class=\"dz-image\"><img data-dz-thumbnail /></div>\n  <div class=\"dz-details\">\n         </div>\n  <div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>\n  <div class=\"dz-error-message\"><span data-dz-errormessage></span></div>\n  <div class=\"dz-success-mark\">\n    \n  </div>\n</div>\',//设置显示模板

        init:function(){
            this.on("removedfile", function(file) {
				return false;
			});
			this.on("addedfile", function(file) {
				return false;
			});
			this.on("success", function(file, responseText) {';
			$parseStr .= '
				$(file.previewTemplate).addClass("success");
				$(file.previewTemplate).find(\'input\').val(responseText);
				//排序
				$(file.previewTemplate).find(".fa-chevron-right").click(function(){
					$(this).parent().parent().next().after($(this).parent().parent());
				});
				$(file.previewTemplate).find(".fa-chevron-left").click(function(){
					$(this).parent().parent().prev().before($(this).parent().parent());
				});
			});
            }});
			
			//初始化排序
			$(".dropzonebox'.$id.' .fa-chevron-right").click(function(){
				$(this).parent().parent().next().after($(this).parent().parent());
			});
			$(".dropzonebox'.$id.' .fa-chevron-left").click(function(){
				$(this).parent().parent().prev().before($(this).parent().parent());
			});
			$(".dropzonebox'.$id.'").find(\'.dz-remove\').click(function(){
				if(!confirm("确定要移除吗？")){
					return false;
				}
				$(this).parent().remove();
			});
		});
</script>';
        return $parseStr;
    }
		
		/**
     * 获得一个上传组件
     */
    public function _headupload($attrtag, $content)
    {
		
		
		$attr        =	$this->parseXmlAttr($attrtag,'headupload');
        $id = $attr['id'];
        $name = $attr['name'];
		$value = $attr['value'];
		$num = !empty($attr['num']) ? $attr['num'] : 1;
		$aspectRatio = !empty($attr['aspectRatio']) ? $attr['aspectRatio'] : 1;
		$width = !empty($attr['width']) ? $attr['width'] : 200;
		$height = !empty($attr['height']) ? $attr['height'] : 200;
		$rotateaction     =	!empty($attr['rotateaction'])?$attr['rotateaction'] :'Img/upload_Img1';
	    $uploadaction     =	!empty($attr['uploadaction'])?$attr['uploadaction'] :'Img/upload_Img1';
	    $jcropaction     =	!empty($attr['jcropaction'])?$attr['jcropaction'] :'Img/Jcrop1';
		$name1 = md5($name);
		$text = !empty($attr['text']) ? $attr['text'] : '选择文件上传';
		$parseStr = '
		
		
		

					<script type="text/javascript">
					
					
					
					
					function uploaded(ret){
						$(".upload-area").show();
						$("#img_src").val(ret.img_url);
						$("input[name=\''.$name.'\']").val(ret.img_url);
						$(".retbox").hide();			 
									 
									 
									 
				$("#upload-areastatus_").show();
				$("#status_").html("正在加载图片，请稍等！");
		        $("#preview-hidden").find("*").remove();
				$("#preview-hidden").hide().addClass("hidden").css({"padding-top":0,"padding-left":0});
				var preview = $(".upload-area").children("#preview-hidden");
				preview.show().removeClass("hidden");
				//两个预览窗口赋值
				$(".crop").children("img").attr("src",ret.img_url+"?random="+Math.random());
				//隐藏表单赋值

				//绑定需要裁剪的图片
				var img = $("<img />");
				preview.append(img);
				preview.children("img").attr("src",ret.img_url+"?random="+Math.random());
				var crop_img = preview.children("img");
				crop_img.attr("id","cropbox").show();
				var img = new Image();
				img.src = ret.img_url+"?random="+Math.random();
				//根据图片大小在画布里居中
				img.onload = function(){
					$("#status_").html("请选择剪切区域");
					setTimeout(function(){
						$("#upload-areastatus_").hide();
					}, 500);
					
					var img_height = 0;
					var img_width = 0;
					var real_height = img.height;
					var real_width = img.width;
					if(real_height > real_width && real_height > '.$height.'){
						var persent = real_height / '.$height.';
						real_height = '.$height.';
						real_width = real_width / persent;
					}else if(real_width > real_height && real_width > '.$width.'){
						var persent = real_width / '.$width.';
						real_width = '.$width.';
						real_height = real_height / persent;
					}
					if(real_height < '.$width.'){
						img_height = ('.$height.' - real_height)/2;	
					}
					if(real_width < '.$width.'){
						img_width = ('.$width.' - real_width)/2;
					}
					preview.css({width:('.$width.'-img_width)+"px",height:('.$height.'-img_height)+"px"});
					preview.css({paddingTop:img_height+"px",paddingLeft:img_width+"px"});			
				}
		
				
				//裁剪插件
				$("#cropbox").Jcrop({
		            bgColor:"#333",   //选区背景色
		            bgFade:true,      //选区背景渐显
		            fadeTime:1000,    //背景渐显时间
		            allowSelect:false, //是否可以选区，
		            allowResize:true, //是否可以调整选区大小
		            aspectRatio: '.$aspectRatio.',     //约束比例
		            minSize : [100,100],//可选最小大小
		            boxWidth : '.$width.',		//画布宽度
		            boxHeight : '.$height.',	//画布高度
		            setSelect:[ 0, 0, 300, 300],//初始化时位置
		            onSelect: function (c){	//选择时动态赋值，该值是最终传给程序的参数！
			            $("#x").val(c.x);//需裁剪的左上角X轴坐标
			            $("#y").val(c.y);//需裁剪的左上角Y轴坐标
			            $("#w").val(c.w);//需裁剪的宽度
			            $("#h").val(c.h);//需裁剪的高度
		          }
		        });
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
								 }
								 
								 
								 
								 
		 function '.$id.'addLoadEventtagUpload(func) { 
			var oldonload = window.onload; 
				if (typeof window.onload != \'function\') { 
				    window.onload = func;
				} else { 
				window.onload = function() { 
				    oldonload();
				func(); 
				} 
			} 
		}
					'.$id.'addLoadEventtagUpload(function(){
						//绑定剪切事件
						$("#Jcropbtn").click(function(e) {
							
							
							$("#upload-areastatus_").show();
							$(\'#status_\').html(\'正在处理\');
							
							var y = $("#y").val();
							var x = $("#x").val();
							var w = $("#w").val();
							var h = $("#h").val();
							var src = $("#img_src").val();
							var img_url = $("input[name=\'img_url\']").val();
							var data = "y="+y+"&x="+x+"&w="+w+"&h="+h+"&src="+src+"&img_url="+img_url;
							$.ajax({
								url:"{:U("'.$jcropaction.'")}",
								data:data,
								dataType:"html",
								type:"POST",
								success: function(ret){
									$("#upload-areastatus_").hide();
									$(".upload-area").hide();
									$("#retimg").attr("src", src);
									$(".retbox").show();
								}
							});
							
						});
						//把文件域放入body中
						var file = $("<input type=\"file\" accept=\".jpg,.gif,.png\" style=\"visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;\">");
						file.appendTo("body");
						file.change(function(e) {
							$("#upload-areastatus_").show();
							$(\'#status_\').html(\'正在压缩图片\');
						});
						$("#headdropz'.$id.'").click(function(e) {
							file.trigger("click");
						});
						
						var url="{:U(\''.$rotateaction.'\')}";
						
						$(".leftimg").click(
	function(){
	var img_urlo=$("input[name=\'img_url\']").val();
	if(img_urlo ==\'\'){alert("请选择图片再做旋转"); return false;}	
	
 		$.post(
		url,
		{imgo:\'left\',imgo_url:img_urlo},
		function(a){ uploaded(a); },
		\'json\'
  		);
 		}
 	);
	
	$(".rightimg").click(
 	function(){
		var img_urlo=$("input[name=\'img_url\']").val();
		if(img_urlo ==\'\'){alert("请选择图片再做旋转"); return false;}	
 		$.post(
		url,
		{imgo:\'right\',imgo_url:img_urlo},
		function(a){ uploaded(a); },
		\'json\'
  		);
 		}
 	);
	

						
						
						
						
						
						
						
						
						file.localResizeIMG({
							 width: 600, 
							 quality: 50,
							 success: function (result) { 
								 var img = new Image();
								 $("#status_").html("正在上传");
								 $.post("{:U("'.$uploadaction.'")}", {png:result.base64}, function(ret){ uploaded(ret); }, "json");
							 }
						 });
						 
						 
					});
						 
						 
					
					</script>
					
					
					<input name="'.$name.'" type="hidden" value="{$'.$value.'}" />  
					<div class="retbox" style="display:none; text-align:center;"><img src="" id="retimg" width="100"></div>
					<div class="upload-area">
					<div style="position:absolute; top:0; left:0; right:0; bottom:0;background:rgba(0,0,0,0.4); display:none; z-index:20000000;" id="upload-areastatus_"><div style="position:absolute; top:40%; text-align:center; width:100%;"><span style="border:1px solid #ffffff;box-shadow: 0px 2px 5px #000;padding:15px 40px; background:#FFFFFF; border-radius:4px;" id="status_"></span></div></div>
					
						<div class="preview hidden" id="preview-hidden"></div>
					</div>
					<div class="preview-area">
						<input type="hidden" id="x" name="x" />
						<input type="hidden" id="y" name="y" />
						<input type="hidden" id="w" name="w" />
						<input type="hidden" id="h" name="h" /> 
						<input type="hidden" id="img_src" name="src" /> 
					</div><br>

					<div style="text-align:center;"><a href="##" class="btn btn-success btn-sm" id="headdropz'.$id.'">'.$text.'</a>
					<a class="btn btn-success btn-sm leftimg" href="##">左旋转</a>
					<a class="btn btn-success btn-sm rightimg" href="##">右旋转</a>
					<a href="##" id="Jcropbtn" class="btn btn-success btn-sm">确认剪切</a></div>
					
					
					
					<style type="text/css">

.cf:before,.cf:after {
	display: table;
	content: "";
	line-height: 0;
}
.cf:after {
	clear: both;
}
.cf {
	*zoom: 1;
}
.upload-area {
	position: relative;
	margin:0 auto;
	width: '.$width.'px;
	height: '.$height.'px;
	background-color: #F5F5F5;
}
.upload-area .file-tips {
	position: absolute;
	top: 90px;
	left: 0;
    padding: 0 15px;
    width: 170px;
    line-height: 1.4;
    font-size: 12px;
	color: #A8A8A3;
    text-align: center;
}
.userup-icon {
    display: inline-block;
    margin-right: 3px;
    width: 16px;
    height: 16px;
    vertical-align: -2px;
	background: url("__ROOT__/public/img/userup_icon.png") no-repeat;
}
.uploadify-button {
	line-height: 120px!important;
	text-align: center;
}
.preview-area {
	float: left;
}
.tcrop {
    clear: right;
    font-size: 14px;
    font-weight: bold;
}
.update-pic .crop {
    background: url("__ROOT__/public/img/mystery.png") no-repeat scroll center center #EEEEEE;
    float: left;
    margin-bottom: 20px;
    margin-top: 10px;
    overflow: hidden;
}
.crop100 {
    height: 100px;
    width: 100px;
}
.crop60 {
    height: 60px;
    margin-left: 20px;
    width: 60px;
}
.update-pic .save-pic {
    clear: left;
    margin-right: 20px;
}
.update-pic .uppic-btn {
    background-color: #348FD4;
    color: #FFFFFF;
    display: block;
    float: left;
    font-size: 16px;
    height: 30px;
    line-height: 30px;
    text-align: center; 
    vertical-align: middle;
    width: 89px;
}
.preview {
	position: absolute;
	top: 0;
	left: 0;
	z-index: 11;
	display: none;
}
</style>';
        return $parseStr;
    }
		
    /**
     +----------------------------------------------------------
     * editor标签解析 插入可视化编辑器
     * 格式： <html:editor id="editor" name="remark" type="FCKeditor" style="" >{$vo.remark}</html:editor>
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _editor($attr,$content) {
        $tag        =	$this->parseXmlAttr($attr,'editor');
        $id			=	!empty($tag['id'])?$tag['id']: '_editor';
        $name   	=	$tag['name'];
        $style   	    =	!empty($tag['style'])?$tag['style']:'';
        $width		=	!empty($tag['width'])?$tag['width']: '100%';
        $height     =	!empty($tag['height'])?$tag['height'] :'320px';
     //   $content    =   $tag['content'];
        $type       =   $tag['type'] ;
		if(isMobile() && $type == 'UEDIT'){
			$type = 'SUMMERNOTE';
		}
        switch(strtoupper($type)) {
            case 'FCKEDITOR':
                $parseStr   =	'<!-- 编辑器调用开始 --><script type="text/javascript" src="__ROOT__/Public/Js/FCKeditor/fckeditor.js"></script><textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "'.$id.'","'.$width.'","'.$height.'" ) ; oFCKeditor.BasePath = "__ROOT__/Public/Js/FCKeditor/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("'.$id.'",document.getElementById("'.$id.'").value)}; function saveEditor(){document.getElementById("'.$id.'").value = getContents("'.$id.'");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("'.$id.'") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else	alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
                break;
            case 'FCKMINI':
                $parseStr   =	'<!-- 编辑器调用开始 --><script type="text/javascript" src="__ROOT__/Public/Js/FCKMini/fckeditor.js"></script><textarea id="'.$id.'" name="'.$name.'">'.$content.'</textarea><script type="text/javascript"> var oFCKeditor = new FCKeditor( "'.$id.'","'.$width.'","'.$height.'" ) ; oFCKeditor.BasePath = "__ROOT__/Public/Js/FCKMini/" ; oFCKeditor.ReplaceTextarea() ;function resetEditor(){setContents("'.$id.'",document.getElementById("'.$id.'").value)}; function saveEditor(){document.getElementById("'.$id.'").value = getContents("'.$id.'");} function InsertHTML(html){ var oEditor = FCKeditorAPI.GetInstance("'.$id.'") ;if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG ){oEditor.InsertHtml(html) ;}else	alert( "FCK必须处于WYSIWYG模式!" ) ;}</script> <!-- 编辑器调用结束 -->';
                break;
            case 'EWEBEDITOR':
                $parseStr	=	"<!-- 编辑器调用开始 --><script type='text/javascript' src='__ROOT__/Public/Js/eWebEditor/js/edit.js'></script><input type='hidden'  id='{$id}' name='{$name}'  value='{$conent}'><iframe src='__ROOT__/Public/Js/eWebEditor/ewebeditor.htm?id={$name}' frameborder=0 scrolling=no width='{$width}' height='{$height}'></iframe><script type='text/javascript'>function saveEditor(){document.getElementById('{$id}').value = getHTML();} </script><!-- 编辑器调用结束 -->";
                break;
            case 'NETEASE':
                $parseStr   =	'<!-- 编辑器调用开始 --><textarea id="'.$id.'" name="'.$name.'" style="display:none">'.$content.'</textarea><iframe ID="Editor" name="Editor" src="__ROOT__/Public/Js/HtmlEditor/index.html?ID='.$name.'" frameBorder="0" marginHeight="0" marginWidth="0" scrolling="No" style="height:'.$height.';width:'.$width.'"></iframe><!-- 编辑器调用结束 -->';
                break;
            case 'UBB':
                $parseStr	=	'<script type="text/javascript" src="__ROOT__/Public/Js/UbbEditor.js"></script><div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript"> showTool(); </script></div><div><TEXTAREA id="UBBEditor" name="'.$name.'"  style="clear:both;float:none;width:'.$width.';height:'.$height.'" >'.$content.'</TEXTAREA></div><div style="padding:1px;width:'.$width.';border:1px solid silver;float:left;"><script LANGUAGE="JavaScript">showEmot();  </script></div>';
                break;
			
			case 'CHENHUIEDITOR':
			    
			    $parseStr ='<textarea id="'.$id.'" style="display:none;'.$style.'" name="'.$name.'" >'.$content.'</textarea>
				<iframe id="iframe'.$id.'" src="__ROOT__/Public/Js/ModelEditor/editor.html?id='.$id.'" frameborder="0" width="'.$width.'" height="'.$height.'"></iframe>';
			    break;
				
            case 'KINDEDITOR':
			
               $parseStr   =  '<script type="text/javascript" src="__ROOT__/Public/Js/KindEditor/kindeditor-min.js"></script><script type="text/javascript">KindEditor.ready(function(K){
					K.create(\'#'.$id.'\', 
					{
						allowFileManager : true,afterBlur: function(){
						document
						.getElementById(
						"'.$id.'"
						)
						.innerHTML = this.html();
						},filterMode:false,uploadJson : "'.U('Kindeditor/upload').'"});
					});</script><textarea id="'.$id.'" style="'.$style.'" name="'.$name.'" >'.$content.'</textarea>';
                break;
			case 'UEDIT' : $parseStr = '
	<script id="'.$id.'" class="ueditorelement" name="'.$name.'" type="text/plain" style="'.$style.'">'.$content.'</script>
	<script>UE.getEditor("'.$id.'",{serverUrl:"'.U('Ueditor/upload').'"});</script>
	'; 
			    break;
				
			case 'SUMMERNOTE' : $parseStr = "<textarea class=\"textarea-content\" name=\"".$name."\" id=\"".$id."\" style=\"".$style."\">".$content."</textarea><script>$('#".$id."').summernote({
        height: 200,
        tabsize: 2,
        codemirror: {
          theme: 'monokai'
        },toolbar: [

    ['style', ['style']], 

    ['style', ['fontname','bold', 'italic', 'underline', 'clear']],

    ['fontsize', ['fontsize']],
		
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']],
    ['insert', ['picture', 'link','hr']], 
	
	['Misc', ['undo','redo']],['fullscreenBtn', ['fullscreen']],
    
  ]
      });</script>";break;
            default :
                $parseStr  =  '<textarea id="'.$id.'" style="'.$style.'" name="'.$name.'" >'.$content.'</textarea>';
        }

        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * imageBtn标签解析
     * 格式： <html:imageBtn type="" value="" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _imageBtn($attr) {
        $tag        = $this->parseXmlAttr($attr,'imageBtn');
        $name       = $tag['name'];                //名称
        $value      = $tag['value'];                //文字
        $id         = isset($tag['id'])?$tag['id']:'';                //ID
        $style      = isset($tag['style'])?$tag['style']:'';                //样式名
        $click      = isset($tag['click'])?$tag['click']:'';                //点击
        $type       = empty($tag['type'])?'button':$tag['type'];                //按钮类型

        if(!empty($name)) {
            $parseStr   = '<div class="'.$style.'" ><input type="'.$type.'" id="'.$id.'" name="'.$name.'" value="'.$value.'" onclick="'.$click.'" class="'.$name.' imgButton"></div>';
        }else {
        	$parseStr   = '<div class="'.$style.'" ><input type="'.$type.'" id="'.$id.'"  name="'.$name.'" value="'.$value.'" onclick="'.$click.'" class="button"></div>';
        }

        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * imageLink标签解析
     * 格式： <html:imageLink type="" value="" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _imgLink($attr) {
        $tag        = $this->parseXmlAttr($attr,'imgLink');
        $name       = $tag['name'];                //名称
        $alt        = $tag['alt'];                //文字
        $id         = $tag['id'];                //ID
        $style      = $tag['style'];                //样式名
        $click      = $tag['click'];                //点击
        $type       = $tag['type'];                //点击
        if(empty($type)) {
            $type = 'button';
        }
       	$parseStr   = '<span class="'.$style.'" ><input title="'.$alt.'" type="'.$type.'" id="'.$id.'"  name="'.$name.'" onmouseover="this.style.filter=\'alpha(opacity=100)\'" onmouseout="this.style.filter=\'alpha(opacity=80)\'" onclick="'.$click.'" align="absmiddle" class="'.$name.' imgLink"></span>';

        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * select标签解析
     * 格式： <html:select options="name" selected="value" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _select($attr) {
        $tag        = $this->parseXmlAttr($attr,'select');
        $name       = $tag['name'];
        $options    = $tag['options'];
        $values     = $tag['values'];
        $output     = $tag['output'];
        $multiple   = $tag['multiple'];
        $id         = $tag['id'];
        $size       = $tag['size'];
        $first      = $tag['first'];
        $selected   = $tag['selected'];
        $style      = $tag['style'];
        $ondblclick = $tag['dblclick'];
		$onchange	= $tag['change'];

        if(!empty($multiple)) {
            $parseStr = '<select id="'.$id.'" name="'.$name.'" ondblclick="'.$ondblclick.'" onchange="'.$onchange.'" multiple="multiple" class="'.$style.'" size="'.$size.'" >';
        }else {
        	$parseStr = '<select id="'.$id.'" name="'.$name.'" onchange="'.$onchange.'" ondblclick="'.$ondblclick.'" class="'.$style.'" >';
        }
        if(!empty($first)) {
            $parseStr .= '<option value="" >'.$first.'</option>';
        }
        if(!empty($options)) {
            $parseStr   .= '<?php  foreach($'.$options.' as $key=>$val) { ?>';
            if(!empty($selected)) {
                /*$parseStr   .= '<?php if(!empty($'.$selected.') && ($'.$selected.' == $key || in_array($key,$'.$selected.'))) { ?>'; 吴俊源 2015-04-16修改,解决键值为0时无法选中的问题*/
				$parseStr   .= '<?php if(($'.$selected.' == $key || in_array($key,$'.$selected.'))) { ?>';
                $parseStr   .= '<option selected="selected" value="<?php echo $key ?>"><?php echo $val ?></option>';
                $parseStr   .= '<?php }else { ?><option value="<?php echo $key ?>"><?php echo $val ?></option>';
                $parseStr   .= '<?php } ?>';
            }else {
                $parseStr   .= '<option value="<?php echo $key ?>"><?php echo $val ?></option>';
            }
            $parseStr   .= '<?php } ?>';
        }else if(!empty($values)) {
            $parseStr   .= '<?php  for($i=0;$i<count($'.$values.');$i++) { ?>';
            if(!empty($selected)) {
                $parseStr   .= '<?php if(isset($'.$selected.') && ((is_string($'.$selected.') && $'.$selected.' == $'.$values.'[$i]) || (is_array($'.$selected.') && in_array($'.$values.'[$i],$'.$selected.')))) { ?>';
                $parseStr   .= '<option selected="selected" value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
                $parseStr   .= '<?php }else { ?><option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
                $parseStr   .= '<?php } ?>';
            }else {
                $parseStr   .= '<option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
            }
            $parseStr   .= '<?php } ?>';
        }
        $parseStr   .= '</select>';
        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * checkbox标签解析
     * 格式： <html:checkbox checkboxes="" checked="" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _checkbox($attr) {
        $tag        = $this->parseXmlAttr($attr,'checkbox');
        $name       = $tag['name'];
        $checkboxes = $tag['checkboxes'];
        $checked    = $tag['checked'];
        $separator  = $tag['separator'];
        $checkboxes = $this->tpl->get($checkboxes);
        $checked    = $this->tpl->get($checked)?$this->tpl->get($checked):$checked;
        $parseStr   = '';
        foreach($checkboxes as $key=>$val) {
            if($checked == $key  || in_array($key,$checked) ) {
                $parseStr .= '<input type="checkbox" checked="checked" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
            }else {
                $parseStr .= '<input type="checkbox" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
            }
        }
        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * radio标签解析
     * 格式： <html:radio radios="name" checked="value" />
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string|void
     +----------------------------------------------------------
     */
    public function _radio($attr) {
        $tag        = $this->parseXmlAttr($attr,'radio');
        $name       = $tag['name'];
        $radios     = $tag['radios'];
        $checked    = $tag['checked'];
        $separator  = $tag['separator'];
        $radios     = $this->tpl->get($radios);
        $checked    = $this->tpl->get($checked)?$this->tpl->get($checked):$checked;
        $parseStr   = '';
        foreach($radios as $key=>$val) {
            if($checked == $key ) {
                $parseStr .= '<input type="radio" checked="checked" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
            }else {
                $parseStr .= '<input type="radio" name="'.$name.'[]" value="'.$key.'">'.$val.$separator;
            }

        }
        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * list标签解析
     * 格式： <html:grid datasource="" show="vo" />
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    public function _grid($attr) {
        $tag        = $this->parseXmlAttr($attr,'grid');
        $id         = $tag['id'];                       //表格ID
        $datasource = $tag['datasource'];               //列表显示的数据源VoList名称
        $pk         = empty($tag['pk'])?'id':$tag['pk'];//主键名，默认为id
        $style      = $tag['style'];                    //样式名
        $name       = !empty($tag['name'])?$tag['name']:'vo';                 //Vo对象名
        $action     = !empty($tag['action'])?$tag['action']:false;                   //是否显示功能操作
        $key         =  !empty($tag['key'])?true:false;
        if(isset($tag['actionlist'])) {
            $actionlist = explode(',',trim($tag['actionlist']));    //指定功能列表
        }

        if(substr($tag['show'],0,1)=='$') {
            $show   = $this->tpl->get(substr($tag['show'],1));
        }else {
            $show   = $tag['show'];
        }
        $show       = explode(',',$show);                //列表显示字段列表

        //计算表格的列数
        $colNum     = count($show);
        if(!empty($action))     $colNum++;
        if(!empty($key))  $colNum++;

        //显示开始
		$parseStr	= "<!-- Think 系统列表组件开始 -->\n";
        $parseStr  .= '<table id="'.$id.'" class="'.$style.'" cellpadding=0 cellspacing=0 >';
        $parseStr  .= '<tr><td height="5" colspan="'.$colNum.'" class="topTd" ></td></tr>';
        $parseStr  .= '<tr class="row" >';
        //列表需要显示的字段
        $fields = array();
        foreach($show as $val) {
        	$fields[] = explode(':',$val);
        }

        if(!empty($key)) {
            $parseStr .= '<th width="12">No</th>';
        }
        foreach($fields as $field) {//显示指定的字段
            $property = explode('|',$field[0]);
            $showname = explode('|',$field[1]);
            if(isset($showname[1])) {
                $parseStr .= '<th width="'.$showname[1].'">';
            }else {
                $parseStr .= '<th>';
            }
            $parseStr .= $showname[0].'</th>';
        }
        if(!empty($action)) {//如果指定显示操作功能列
            $parseStr .= '<th >操作</th>';
        }
        $parseStr .= '</tr>';
        $parseStr .= '<volist name="'.$datasource.'" id="'.$name.'" ><tr class="row" >';	//支持鼠标移动单元行颜色变化 具体方法在js中定义

        if(!empty($key)) {
            $parseStr .= '<td>{$i}</td>';
        }
        foreach($fields as $field) {
            //显示定义的列表字段
            $parseStr   .=  '<td>';
            if(!empty($field[2])) {
                // 支持列表字段链接功能 具体方法由JS函数实现
                $href = explode('|',$field[2]);
                if(count($href)>1) {
                    //指定链接传的字段值
                    // 支持多个字段传递
                    $array = explode('^',$href[1]);
                    if(count($array)>1) {
                        foreach ($array as $a){
                            $temp[] =  '\'{$'.$name.'.'.$a.'|addslashes}\'';
                        }
                        $parseStr .= '<a href="javascript:'.$href[0].'('.implode(',',$temp).')">';
                    }else{
                        $parseStr .= '<a href="javascript:'.$href[0].'(\'{$'.$name.'.'.$href[1].'|addslashes}\')">';
                    }
                }else {
                    //如果没有指定默认传编号值
                    $parseStr .= '<a href="javascript:'.$field[2].'(\'{$'.$name.'.'.$pk.'|addslashes}\')">';
                }
            }
            if(strpos($field[0],'^')) {
                $property = explode('^',$field[0]);
                foreach ($property as $p){
                    $unit = explode('|',$p);
                    if(count($unit)>1) {
                        $parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} ';
                    }else {
                        $parseStr .= '{$'.$name.'.'.$p.'} ';
                    }
                }
            }else{
                $property = explode('|',$field[0]);
                if(count($property)>1) {
                    $parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}';
                }else {
                    $parseStr .= '{$'.$name.'.'.$field[0].'}';
                }
            }
            if(!empty($field[2])) {
                $parseStr .= '</a>';
            }
            $parseStr .= '</td>';

        }
        if(!empty($action)) {//显示功能操作
            if(!empty($actionlist[0])) {//显示指定的功能项
                $parseStr .= '<td>';
                foreach($actionlist as $val) {
					if(strpos($val,':')) {
						$a = explode(':',$val);
						if(count($a)>2) {
                            $parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$a[2].'}\')">'.$a[1].'</a>&nbsp;';
						}else {
							$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$pk.'}\')">'.$a[1].'</a>&nbsp;';
						}
					}else{
						$array	=	explode('|',$val);
						if(count($array)>2) {
							$parseStr	.= ' <a href="javascript:'.$array[1].'(\'{$'.$name.'.'.$array[0].'}\')">'.$array[2].'</a>&nbsp;';
						}else{
							$parseStr .= ' {$'.$name.'.'.$val.'}&nbsp;';
						}
					}
                }
                $parseStr .= '</td>';
            }
        }
        $parseStr	.= '</tr></volist><tr><td height="5" colspan="'.$colNum.'" class="bottomTd"></td></tr></table>';
        $parseStr	.= "\n<!-- Think 系统列表组件结束 -->\n";
        return $parseStr;
    }

    /**
     +----------------------------------------------------------
     * list标签解析
     * 格式： <html:list datasource="" show="" />
     *
     +----------------------------------------------------------
     * @access public
     +----------------------------------------------------------
     * @param string $attr 标签属性
     +----------------------------------------------------------
     * @return string
     +----------------------------------------------------------
     */
    public function _list($attr) {
        $tag        = $this->parseXmlAttr($attr,'list');
        $id         = $tag['id'];                       //表格ID
        $datasource = $tag['datasource'];               //列表显示的数据源VoList名称
        $pk         = empty($tag['pk'])?'id':$tag['pk'];//主键名，默认为id
        $style      = $tag['style'];                    //样式名
        $name       = !empty($tag['name'])?$tag['name']:'vo';                 //Vo对象名
        $action     = $tag['action']=='true'?true:false;                   //是否显示功能操作
        $key         =  !empty($tag['key'])?true:false;
        $sort      = $tag['sort']=='false'?false:true;
        $checkbox   = $tag['checkbox'];                 //是否显示Checkbox
        if(isset($tag['actionlist'])) {
            $actionlist = explode(',',trim($tag['actionlist']));    //指定功能列表
        }

        if(substr($tag['show'],0,1)=='$') {
            $show   = $this->tpl->get(substr($tag['show'],1));
        }else {
            $show   = $tag['show'];
        }
        $show       = explode(',',$show);                //列表显示字段列表

        //计算表格的列数
        $colNum     = count($show);
        if(!empty($checkbox))   $colNum++;
        if(!empty($action))     $colNum++;
        if(!empty($key))  $colNum++;

        //显示开始
		$parseStr	= "<!-- Think 系统列表组件开始 -->\n";
        $parseStr  .= '<table id="'.$id.'" class="'.$style.'" cellpadding=0 cellspacing=0 >';
        $parseStr  .= '<tr><td height="5" colspan="'.$colNum.'" class="topTd" ></td></tr>';
        $parseStr  .= '<tr class="row" >';
        //列表需要显示的字段
        $fields = array();
        foreach($show as $val) {
        	$fields[] = explode(':',$val);
        }
        if(!empty($checkbox) && 'true'==strtolower($checkbox)) {//如果指定需要显示checkbox列
            $parseStr .='<th width="8"><input type="checkbox" id="check" onclick="CheckAll(\''.$id.'\')"></th>';
        }
        if(!empty($key)) {
            $parseStr .= '<th width="12">No</th>';
        }
        foreach($fields as $field) {//显示指定的字段
            $property = explode('|',$field[0]);
            $showname = explode('|',$field[1]);
            if(isset($showname[1])) {
                $parseStr .= '<th width="'.$showname[1].'">';
            }else {
                $parseStr .= '<th>';
            }
            $showname[2] = isset($showname[2])?$showname[2]:$showname[0];
            if($sort) {
                $parseStr .= '<a href="javascript:sortBy(\''.$property[0].'\',\'{$sort}\',\''.ACTION_NAME.'\')" title="按照'.$showname[2].'{$sortType} ">'.$showname[0].'<eq name="order" value="'.$property[0].'" ><img src="../Public/images/{$sortImg}.gif" width="12" height="17" border="0" align="absmiddle"></eq></a></th>';
            }else{
                $parseStr .= $showname[0].'</th>';
            }

        }
        if(!empty($action)) {//如果指定显示操作功能列
            $parseStr .= '<th >操作</th>';
        }

        $parseStr .= '</tr>';
        $parseStr .= '<volist name="'.$datasource.'" id="'.$name.'" ><tr class="row" ';	//支持鼠标移动单元行颜色变化 具体方法在js中定义
        if(!empty($checkbox)) {
            $parseStr .= 'onmouseover="over(event)" onmouseout="out(event)" onclick="change(event)" ';
        }
        $parseStr .= '>';
        if(!empty($checkbox)) {//如果需要显示checkbox 则在每行开头显示checkbox
            $parseStr .= '<td><input type="checkbox" name="key"	value="{$'.$name.'.'.$pk.'}"></td>';
        }
        if(!empty($key)) {
            $parseStr .= '<td>{$i}</td>';
        }
        foreach($fields as $field) {
            //显示定义的列表字段
            $parseStr   .=  '<td>';
            if(!empty($field[2])) {
                // 支持列表字段链接功能 具体方法由JS函数实现
                $href = explode('|',$field[2]);
                if(count($href)>1) {
                    //指定链接传的字段值
                    // 支持多个字段传递
                    $array = explode('^',$href[1]);
                    if(count($array)>1) {
                        foreach ($array as $a){
                            $temp[] =  '\'{$'.$name.'.'.$a.'|addslashes}\'';
                        }
                        $parseStr .= '<a href="javascript:'.$href[0].'('.implode(',',$temp).')">';
                    }else{
                        $parseStr .= '<a href="javascript:'.$href[0].'(\'{$'.$name.'.'.$href[1].'|addslashes}\')">';
                    }
                }else {
                    //如果没有指定默认传编号值
                    $parseStr .= '<a href="javascript:'.$field[2].'(\'{$'.$name.'.'.$pk.'|addslashes}\')">';
                }
            }
            if(strpos($field[0],'^')) {
                $property = explode('^',$field[0]);
                foreach ($property as $p){
                    $unit = explode('|',$p);
                    if(count($unit)>1) {
                        $parseStr .= '{$'.$name.'.'.$unit[0].'|'.$unit[1].'} ';
                    }else {
                        $parseStr .= '{$'.$name.'.'.$p.'} ';
                    }
                }
            }else{
                $property = explode('|',$field[0]);
                if(count($property)>1) {
                    $parseStr .= '{$'.$name.'.'.$property[0].'|'.$property[1].'}';
                }else {
                    $parseStr .= '{$'.$name.'.'.$field[0].'}';
                }
            }
            if(!empty($field[2])) {
                $parseStr .= '</a>';
            }
            $parseStr .= '</td>';

        }
        if(!empty($action)) {//显示功能操作
            if(!empty($actionlist[0])) {//显示指定的功能项
                $parseStr .= '<td>';
                foreach($actionlist as $val) {
					if(strpos($val,':')) {
						$a = explode(':',$val);
						if(count($a)>2) {
                            $parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$a[2].'}\')">'.$a[1].'</a>&nbsp;';
						}else {
							$parseStr .= '<a href="javascript:'.$a[0].'(\'{$'.$name.'.'.$pk.'}\')">'.$a[1].'</a>&nbsp;';
						}
					}else{
						$array	=	explode('|',$val);
						if(count($array)>2) {
							$parseStr	.= ' <a href="javascript:'.$array[1].'(\'{$'.$name.'.'.$array[0].'}\')">'.$array[2].'</a>&nbsp;';
						}else{
							$parseStr .= ' {$'.$name.'.'.$val.'}&nbsp;';
						}
					}
                }
                $parseStr .= '</td>';
            }
        }
        $parseStr	.= '</tr></volist><tr><td height="5" colspan="'.$colNum.'" class="bottomTd"></td></tr></table>';
        $parseStr	.= "\n<!-- Think 系统列表组件结束 -->\n";
        return $parseStr;
    }
    
	//重构下拉框
	public function _dropdownselect($attr){
		$tag        = $this->parseXmlAttr($attr,'dropdownselect');
        $name       = $tag['name'];
		$id         = $tag['id'];
		$class      = $tag['class'];
		$style      = $tag['style'];
		$title      = $tag['title'];
		$datatype   = $tag['datatype'];
		$multi   = $tag['multi'] == '' ? 0 : $tag['multi'];
		$selected   = $tag['selected'] == '' ? 0 : $tag['selected'];
		$typelimit  = $tag['typelimit']==1 ? 1 : 0;
		$datatype   = $tag['datatype'];
		$action        = $tag['action'];
        $placeholder    =$tag['placeholder'];
		$listloaded        = $tag['listloaded'];
		$strtime = microtime_float() * 10000+mt_rand(0,100);
		
		$styletext = '<style>
		#selectlist'.$name.''.$strtime.'{padding:0; margin:0;}
		#selectlist'.$name.''.$strtime.' .selectitem:hover{background-color:#eee;}
		#selectlist'.$name.''.$strtime.' ul{padding-left:0;}
		#selectlist'.$name.''.$strtime.' .selectitem{display:block !important; padding:2px 5px;}
    #selectlist'.$name.''.$strtime.' ul ul{padding-left:1em;}
    #selectlist'.$name.''.$strtime.' ul li{list-style-type:none;}
	#selectlist'.$name.''.$strtime.' ul li ul{display:none;}
	#selectlist'.$name.''.$strtime.' ul li ul.open{display:block;}
	#selectlist'.$name.''.$strtime.' .tree-btn{cursor: pointer;
	float:left;
	margin-top:3px;
  font-style: normal;
  border: 1px solid #ccc;
  line-height: 18px;
  background:#fff;
  display: inline-block; 
  margin-right: 5px;width:18px; height:18px; border-radius:2px; text-align:center;}
	
	#reselect'.$name.''.$strtime.'{box-shadow: 0 0 3px #eee; border:1px solid #ccc;}
	#reselect'.$name.'input'.$strtime.':hover{border-color:#999;}
	
	#reselect'.$name.'input'.$strtime.'{cursor:pointer;width:400px; min-height:35px; line-height:35px; border:1px solid #ccc; background:#fff; padding:0 8px; border-radius:4px;}</style>';
	
	
	
	if(isMobile()){
		$styletext.= '<style>#reselect'.$name.'{top:0 !important; left:0 !important; bottom:0 !important; right:0 !important; width:auto !important; margin-bottom:0;border-radius:0 !important; }
		
		</style>';
	}
	
	
		$html = $styletext.'<div id="reselect'.$name.'input'.$strtime.'" style="'.$style.'" class="'.$class.'" multi="'.$multi.'" style=""><span style="cursor:pointer" id="placeholder'.$strtime.'">'.$placeholder.'</span></div>';
		$html .= '
		<div class="panel" id="reselect'.$name.''.$strtime.'" style="position:fixed; background:#fff; top:30px; left:30px; z-index:5000; width:300px; display:none;">
		  <div class="panel-body"><div class="row" style="margin-bottom:15px;">
			  <div class="col-md-12">
				
				  <div class="input-group">
					  <input type="text" name="keywords" class="form-control" placeholder="请输入关键词匹配搜索">
					  <span class="input-group-btn">
					  <button type="submit" class="btn btn-default"><i class="fa icon-search"></i></button>
					  </span> </div>
				
			  </div>
			</div>
			<div id="selectlist'.$name.''.$strtime.'scroll"><ul class="ui-sortable selectlist" id="selectlist'.$name.''.$strtime.'" style="height:300px; overflow:hidden; overflow-y:scroll;">
			</ul>
			<div id="selectlist'.$name.''.$strtime.'pages"></div></div>';
			
			if($multi > 0){
				$html .= '<a id="selectlist'.$name.''.$strtime.'confirm" onClick="selectlist'.$name.''.$strtime.'close();" style="margin-top:15px; border-radius:0; width:100%;" class="btn btn-success btn-sm" href="javascript:void(0);">确定</a>';
			}
			
		$html .= '
		  </div>
		</div>
		
		<script>
		function selectlist'.$name.''.$strtime.'close(){
			var reselect = $("#reselect'.$name.''.$strtime.'");
			var reselectlayout = $("#reselect'.$name.'layout");
			var reselectinput = $("#reselect'.$name.'input'.$strtime.'");
			reselectlayout.hide();
			reselect.hide();
			//reselectinput.trigger("blur");
		}
		function reselect'.$strtime.'addLoadEvent(func) { 
			var oldonload = window.onload; 
				if (typeof window.onload != \'function\') { 
				    window.onload = func;
				} else { 
				window.onload = function() { 
				    oldonload();
				func(); 
				} 
			} 
		}
		
		reselect'.$strtime.'addLoadEvent(function(){
			
			
			//当控件存在时，不重新绑定事件，防止重复执行这个事件导致多次回调
			window.onload = function(){};
			
			//移除旧的控件，页面不能存在两个一样的控件
			//窗口中的元素要移除，其它保留原样
			
			//$(".isaui_state_focus").parent("form.form-inline.selectlist.'.str_replace(' ', '', $class).'").remove();
			
			$(\'<div id="reselect'.$name.'layout" style="top:0; display:none; left:0; bottom:0; right:0; position:fixed; z-index:4999;"></div>\').appendTo("body");
			if($("#reselect'.$name.''.$strtime.'").parents(".aui_state_focus").length > 0){
				$("#reselect'.$name.''.$strtime.'").addClass("isaui_state_focus");
			}
			$("#reselect'.$name.''.$strtime.'").appendTo("body");
			
			
			if($("#reselect'.$name.''.$strtime.'").parent("form").length == 0){
			    $("#reselect'.$name.''.$strtime.'").wrap(\'<form class="form-inline selectlist '.str_replace(' ', '', $class).'" id="selectlist'.$name.''.$strtime.'form" action="'.$action.'">\');
			}
			
			
			$("#selectlist'.$name.'form").addClass("binded");
			
			
			//防止多次绑定事件
			
			if(!$("#reselect'.$name.'input'.$strtime.'").hasClass("binded")){
				$("#reselect'.$name.'input'.$strtime.'").addClass("binded");
				$("#reselect'.$name.'input'.$strtime.'").click(function(e) {
					var top = $(this).offset().top - $(document).scrollTop();
					var windowheight = $(window).height();
					var left = $(this).offset().left;
					var reselect = $("#reselect'.$name.''.$strtime.'");
					var reselectlayout = $("#reselect'.$name.'layout");
					var selectheight = reselect.height();
					if(windowheight - top - $(this).outerHeight() > reselect.outerHeight()){
						//alert(top + $(this).height());
						reselect.css({top: top + $(this).height() + "px", left: left + "px"});
					}else{
						
						reselect.css({top: top - reselect.outerHeight() + "px", left: left + "px"});
					}
					
					
					var windowwidth = $(window).width();
					var selectwidth = reselect.outerWidth();
					var left = reselect.css("left").replace("px", "")*1;
					var sw = windowwidth - (left + selectwidth);
					if(sw < 0){
						
						reselect.css({left: (left + sw) + "px"});
					}
					
					
					$("#selectlist'.$name.''.$strtime.'scroll").niceScroll({
                            styler: "fb",
                            cursorcolor: "#65cea7", 
                            cursorwidth: "3",
                            cursorborderradius: "0px",
                            background: "#424f63",
                            spacebarenabled: false,
                            cursorborder: "0"
                        });
					reselectlayout.show();
					reselect.show(50);
				});
			}
			
			
			
			$("#selectlist'.$name.''.$strtime.'").ajaxlist({success:function(){ ';
				
				
				if(isMobile()){
				     $html .= '$("#selectlist'.$name.''.$strtime.'scroll").css("height",$(window).height() - 104 + "px");
					 $("#selectlist'.$name.''.$strtime.'").css("height","auto");
					 ';
				}
				
				$html .= '
				
				
				var reselect = $("#reselect'.$name.''.$strtime.'");
				var reselectlayout = $("#reselect'.$name.'layout");
				var reselectinput = $("#reselect'.$name.'input'.$strtime.'");
				if(!reselectlayout.hasClass("binded")){
					reselectlayout.click(function(e) {
						reselectlayout.hide();
						reselect.hide();
					});
				}
				if(!$("#selectlist'.$name.''.$strtime.'").hasClass("listloaded")){
					//alert();
				$("#selectlist'.$name.''.$strtime.'").addClass("listloaded");
				';
				
				
				if($listloaded != ''){
					$html .= $listloaded.'();';
				}
				
				$html .='
				}
				$("#selectlist'.$name.''.$strtime.' em.tree-btn").each(function(){
					if($(this).parent().find("ul:eq(0)").length == 0){
						$(this).remove();
					}
				});
				$("#selectlist'.$name.''.$strtime.' em.tree-btn").click(function(e){
					
					
					
					if($(this).parent().find("ul:eq(0)").hasClass("open")){
						$(this).parent().find("ul:eq(0)").removeClass("open");
						$(this).html("+");
					}else{
						$(this).parent().find("ul:eq(0)").addClass("open");
						$(this).html("-");
					}
				});
				
				
				reselect.find(".selectitem").click(function(e){
					$("#placeholder'.$strtime.'").remove();
					';
					if($typelimit==1){
						$html.='if($(this).prev("em").length==1){return;}';
					}
					$html.='
					if(reselectinput.attr("multi") == "1"){
						var selected = new Array();
						var selectdata = $(this).find(".dataitem");
						
						if(!selectdata.hasClass("clicked")){
							selectdata.find("input[type=\"hidden\"]").each(function(){
								$(this).attr("name", "'.$name.'_"+$(this).attr("name")+"[]");
							});
							selectdata.addClass("clicked");
						}
						var reselectinputc;
						selectdata.find("input[type=\"hidden\"]").each(function(){
							reselectinputc = reselectinput.find("input[value=\""+$(this).attr("value")+"\"][name=\""+$(this).attr("name")+"\"]");
							if(reselectinputc.length > 0){
								selected.push(1);
							}
						});
						
						if(selectdata.find("input[type=\"hidden\"]").length == selected.length){
							$(this).removeClass("selected");
							reselectinputc.parent().remove();
							
						}else{
							$(this).addClass("selected");
							reselectinput.append(selectdata.html());
						}
						
						
						reselectinput.trigger("blur");
					}else{

						reselect.find(".selectitem").removeClass("selected");
						$(this).addClass("selected");
						var selectdata = $(this).find(".dataitem");
						if(!selectdata.hasClass("clicked")){
						    selectdata.find("input[type=\"hidden\"]").each(function(){
								
								
								
						        $(this).attr("name", "'.$name.'_"+$(this).attr("name"));
						    });
							selectdata.addClass("clicked");
						}
						
						//alert($(this).find(".dataitem").html());
						reselectinput.html($(this).find(".dataitem").html());
						selectlist'.$name.''.$strtime.'close();
						reselectinput.trigger("blur");
					}
					
					reselectinput.find(".deletedata").each(function(index, element) {
						$(this).click(function(e) {
							$(this).parent().remove();
							reselectinput.trigger("blur");
							e.stopPropagation();
							if($("#reselect'.$name.'input'.$strtime.'").html()){ $("#reselect'.$name.'input'.$strtime.'").html("<span style=\'cursor:pointer\' id=\'placeholder'.$strtime.'\'>'.$placeholder.'</span>");}
						});
						$(this).removeClass("deletedata");
					});
					
				});
			}});
			
		});
		</script>';
		return $html;
	}
	
	
	
	
	
	//2016 9 13 加了一个another name用来扩展第二个input的值
	public function _listselect($attr) {
        $tag        = $this->parseXmlAttr($attr,'customer');
        $name       = $tag['name'];
		$id         = $tag['id'];
		$class      = $tag['class'];
		$style      = $tag['style'];
		$title      = $tag['title'];
		$datatype   = $tag['datatype'];
		$multiple   = $tag['multiple'] == '' ? 0 : $tag['multiple'];
		$selected   = $tag['selected'] == '' ? 0 : $tag['selected'];
		$datatype   = $tag['datatype'];
		$url        = $tag['url'];
        $anothername= isset($tag['anothername'])?$tag['anothername']:'';
		//return $url;
		$strtime = microtime_float() * 10000;
		$ret = '<div ismobile="'.isMobile().'" class="'.$name.'Box"><div class="'.$name.'DataBox Box'.$strtime.'">加载中……</div><a style="'.$style.'" class="'.$class.'" href="javascript:void(0);" onClick="_openWindow'.$name.''.$strtime.'()">'.$title.'</a></div>';
		$ret .= '<style>.SelectDataListItem .icon-ok-sign{color:#1BAB2B; display:none; font-size:16px !important;}
	.SelectDataListItem .icon-circle-blank{color:#1BAB2B; display:inline-block; color:#eee; font-size:16px !important;}
	.SelectDataListItem.selected .icon-ok-sign{display:inline-block !important; visibility:visible !important;}
	.SelectDataListItem.selected .icon-circle-blank{display:none !important; visibility:hidden !important;}
	.auii_statei_focus'.$name.' .aui_content{padding:5px !important;}
	.SelectDataListItem{background-color:#fff;}
</style>';
		
		$ret .= '<script>
		
		
		
		
		function '.$name.'lockwindow(){';
		if(isMobile()){
		$ret .= 'var html = \'<div id="lockwindowlayout" style="background-color:rgba(255,255,255,0.2); position:fixed; bottom:0; top:0; left:0; right:0; z-index:20000000;"><div class="loader-inner line-scale" style="position:absolute;top:50%; width:100%; margin-top:-50px; text-align:center;"><div></div><div></div><div></div><div></div><div></div></div><style>#lockwindowlayout .line-scale div{background:#5ec8ff;}.aui_state_focus{opacity:0;}</style></div>\';
		$("body").append(html);
		';
		}
		$ret .= '
	}
		
		function '.$name.'DataBoxBox'.$strtime.'addLoadEvent(func) { 
			var oldonload = window.onload; 
				if (typeof window.onload != \'function\') { 
				    window.onload = func;
				} else { 
				window.onload = function() { 
				    oldonload();
				func(); 
				} 
			} 
		} 
		
		
		
		function '.$name.'select'.$strtime.'(){
		$(".auii_statei_focus'.$name.' .SelectDataListItem").click(function(e) {
			
				if(!$(this).hasClass("selected")){
					//不允许多选
					
					if('.$multiple.' == 0){
						$(".auii_statei_focus'.$name.' .SelectDataListItem").removeClass("selected");
						$(this).addClass("selected");
						$(this).find(".DataBox input").each(function(){
								
							    $(this).attr("name", "'.$name.'_"+$(this).attr("name"));
								
						    });
							
						$(".Box'.$strtime.'.'.$name.'DataBox").html($(this).find(".DataBox").html());
					}else{
						$(this).addClass("selected");
						//添加数据
						var sval = $(this).find(".DataBox input").val();
						if($(".Box'.$strtime.'.'.$name.'DataBox input[value=\'"+sval+"\']").length == 0){
							
							
							$(this).find(".DataBox input").each(function(){
								
							    $(this).attr("name", "'.$name.'_"+$(this).attr("name")+"[]");
								
						    });
							
							$(".Box'.$strtime.'.'.$name.'DataBox").find(".checkforminput").remove();
							$(".Box'.$strtime.'.'.$name.'DataBox").append($(this).find(".DataBox").html());
						}
					}
				}else{ 
					$(this).removeClass("selected");
				}
				
			});
		

	}
		
		function '.$name.'PageInit(){
			
			
			//下拉框
			$(".auii_statei_focus'.$name.' .PagesBox select").each(function(index, element) {
                element.onchange = function(){
					var url = $(this).val();
					$.get(url,{},function(data){
						$(".auii_statei_focus'.$name.' .aui_content").html(data.tbody);
						'.$name.'select'.$strtime.'(); 
						'.$name.'PageInit();
					},"json")
				}
            });
			
			
			
			
			
			
			
			
		    $(".auii_statei_focus'.$name.' .PagesBox").find("a").each(function(e) {
			var url = $(this).attr("href");
			$(this).attr("href", "javascript:void(0);");
			$(this).attr("rel", url);
			
			
			
			$(this).click(function(e){
                $.get(url, {}, function(data){
						$(".auii_statei_focus'.$name.' .aui_content").html(data.tbody);
						'.$name.'select'.$strtime.'(); 
						//绑定分页事件
						'.$name.'PageInit();
					}, "json");
				});
            });
		

	}
		
		
	';

	if($selected !== 0){
		
			
			if(intval($selected) > 0){
				$ret .= ''.$name.'DataBoxBox'.$strtime.'addLoadEvent(function(){
					if("'.$selected.'".split(",")[0]*1 > 0){
					
					
					
			$.get("'.$url.'",{selected:"'.$selected.'"},function(data){
				$(".Box'.$strtime.'").html(data.tbody);
				$(".Box'.$strtime.' input").each(function(index,element){
					 $(this).attr("name", "'.$name.'_"+$(this).attr("name"));
				});
			},"json");
			';
			
			$ret .= '
		}else{
			
			try
{
			document.getElementsByClassName("Box'.$strtime.'").item(0).innerHTML = \'<input class="checkforminput" type="hidden" name=\"'.$name.'\" ';
			if($datatype != ''){
				$ret .= 'datatype=\"'.$datatype.'\"';
			}
			$ret .= '>\'}
catch(err)
{
  
};
			}});
		
	';
			}else{
				$ret .= ''.$name.'DataBoxBox'.$strtime.'addLoadEvent(function(){
					if("<?php echo $'.$selected.'; ?>" != ""){
			$.get("'.$url.'",{selected:"<?php echo $'.$selected.';?>"},function(data){
				$(".Box'.$strtime.'").html(data.tbody);
				$(".Box'.$strtime.' input").each(function(index,element){
					 $(this).attr("name", "'.$name.'_"+$(this).attr("name"));
				});
			},"json");
		}else{
			try
{document.getElementsByClassName("Box'.$strtime.'").item(0).innerHTML = \'<input class="checkforminput" type="hidden" name="'.$name.'" ';
		if($datatype != ''){
			$ret .= 'datatype=\"'.$datatype.'\"';
		}
		$ret .= '>\'}
catch(err)
{
  
};
			
		}});';
			}
			
			
	}else{
		$ret .= 'try
{

document.getElementsByClassName("Box'.$strtime.'").item(0).innerHTML = \'<input class="checkforminput" type="hidden" name="'.$name.'"     ';
		//$ret .= '$(".'.$name.'DataBox").html(\'<input class="checkforminput" type="hidden" name=\"'.$name.'\" ';

//        >\';document.getElementsByTagName("form").innerHTML = \'<input class="checkforminput" id='hidinp' type="hidden" name="'.$name.'"
		if($datatype != ''){
			$ret .= 'datatype=\"'.$datatype.'\"';
		}
		$ret .= '>\';}
catch(err)
{
  
}';
	}
			
		
	
	$ret .= '
		function _openWindow'.$name.''.$strtime.'(){
		
		var lock = true;
		var height = $(window).height() - 200;
		var width = 700;
		';
		
		if(isMobile()){
			$ret .= 'width = "100%";
			lock = false;
			'.$name.'lockwindow();
			var height = $(window).height() - 45;';
		}
		$ret .= 'var mydialog = art.dialog.load("'.$url.'",{init:function(){
			
			
			$(".aui_state_focus").addClass("auii_statei_focus auii_statei_focus'.$name.'");
			
			
			
			$(".auii_statei_focus'.$name.' #selectdatalist").ajaxlist({success:function(){
				'.$name.'select'.$strtime.'();
			}});
			
			 
			
			
			';
			if(isMobile()){
			$ret .= '$(".modal-shiftfix").addClass("hidden");
			//弹出窗口后把其它窗口隐藏起来
			$(".auii_statei_focus").hide();
			$("body").addClass("padding0");
			$("#lockwindowlayout").remove();
			$(".aui_state_focus").addClass("auii_statei_focus auii_statei_focus'.$name.'");
			var index = $(".auii_statei_focus").length;
			index ++;
			$(".aui_state_focus").attr("index", index);
			$(".aui_state_focus .aui_close").text("").addClass("icon-angle-left");
			$(".aui_state_focus").addClass("index"+index);
			
			if($(".aui_state_focus .aui_main").height() > $(window).height() - 100){
				
				$(".aui_state_focus .aui_main").height($(window).height() - 200);
				
				var niceScroll = $(".aui_state_focus .aui_main").niceScroll({styler:"fb",cursorcolor:"#65cea7", cursorwidth: "3", cursorborderradius: "0px", background: "#424f63", spacebarenabled:false, cursorborder: "0"});
				
				
			}
			mydialog._reset();
			$(".aui_state_focus").css({"animationDuration":"0.3s"}).addClass("animated slideInLeft").one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function(){
					
					//动画结束后可能有退场动作，通过判断是否有退场属性来执行
					
					$(".aui_state_focus").removeClass("animated slideInLeft");
				});
			$(".aui_state_focus").animate({opacity:1},100);
			
			
			//插入按钮前要清空原来的按钮
			$(".auii_statei_focus'.$name.' .aui_titleBar button").remove();
			var okBtn = $(".auii_statei_focus'.$name.' .aui_buttons").html();
			$(".auii_statei_focus'.$name.' .aui_buttons").hide();
			$(okBtn).insertAfter(".aui_state_focus .aui_close");
			$(".auii_statei_focus'.$name.' .aui_titleBar button").each(function(index, element) {
                $(this).click(function(e) {
                    $(".auii_statei_focus'.$name.' .aui_buttons button").eq(index).trigger("click");
                });
            });';
		}
			
			$ret .= '
			if($(".aui_state_focus .aui_main").height() > $(window).height() - 100){
				
				$(".aui_state_focus .aui_main").height($(window).height() - 200);
				
				var niceScroll = $(".aui_state_focus .aui_main").niceScroll({styler:"fb",cursorcolor:"#65cea7", cursorwidth: "3", cursorborderradius: "0px", background: "#424f63", spacebarenabled:false, cursorborder: "0"});
				
				$(".aui_state_focus .aui_main").click(function (e) {
							
                            $("#"+niceScroll.id).css("z-index", $("#"+niceScroll.id).css("z-index")*1+1);
                        });
			}
			
			mydialog._reset();
			$.cookie("scroll_hidden",$(document).scrollTop());
			
			
		},width: width, height: "auto",fixed:true,lock:lock,opacity:0.5,duration:0,title:"'.$title.'",ok:function(){
			
			
			mydialog.close();
			
			return false;
		},okVal:"确定",close:function(){';
			
			
		if(isMobile()){
			$ret .= '
			if($(".auii_statei_focus").length > 1){
				
				$(".auii_statei_focus.index"+($(".aui_state_focus").attr("index")*1 - 1)).show().addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie("scroll_hidden")},100);
				$(".modal-shiftfix").removeClass("hidden");
				$("body").removeClass("padding0");
			}';
			
		}else{
			
			$ret .= '
			
			
			$(".aui_state_focus .aui_main").getNiceScroll().remove();
			
			if($(".aui_state_lock").length > 0){
			    $(".aui_state_lock").addClass("aui_state_focus");
			}else{
				$("html,body").animate({scrollTop:$.cookie("scroll_hidden")},100);
				$(".modal-shiftfix").removeClass("hidden");
				$("body").removeClass("padding0");
			}';
		}
			
			$ret .= '
			
			
		}, content:"加载中……"});
	}
</script>';
		return $ret;
    }
	
}
?>